/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.goods.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.config.MyProps;
import com.jeesite.modules.goods.entity.ZtColor;
import com.jeesite.modules.goods.entity.ZtGoods;
import com.jeesite.modules.goods.entity.ZtJDorder;
import com.jeesite.modules.goods.entity.ZtQuan;
import com.jeesite.modules.goods.entity.ZtQuanself;
import com.jeesite.modules.goods.entity.ZtSpecifications;
import com.jeesite.modules.goods.service.ZtColorService;
import com.jeesite.modules.goods.service.ZtGoodsService;
import com.jeesite.modules.goods.service.ZtJDorderService;
import com.jeesite.modules.goods.service.ZtQuanselfService;
import com.jeesite.modules.goods.service.ZtSpecificationsService;
import com.jeesite.modules.sys.service.DictDataService;
import com.jeesite.modules.sys.service.UserService;
import com.jeesite.modules.sys.utils.DictUtils;
import com.jeesite.modules.xcxAdmin.entity.ZtAdmin;

/**
 * 测试数据Controller
 * 
 * @author ThinkGem
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${adminPath}/ztJDorder")
public class ZtJDorderController extends BaseController {

	@Autowired
	private ZtJDorderService ztJDorderService;

	@Autowired
	private UserService userService;
	
	@Autowired
	private ZtColorService ztColorService;
	@Autowired
	private ZtSpecificationsService specificationsService;

	@Autowired
	private ZtGoodsService ztGoodsService;

	@Autowired
	private ZtQuanselfService ztQuanselfService;

	@Autowired
	private MyProps myProps;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ZtJDorder get(String id, boolean isNewRecord) {
		ZtJDorder ztJDorder = new ZtJDorder();
		if (StringUtils.isNotBlank(id)) {
			ztJDorder.setId(id);
			ztJDorder = ztJDorderService.get(ztJDorder);
		}
		if (ztJDorder == null) {
			ztJDorder = new ZtJDorder();
		}
		return ztJDorder;
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("ztJDorder:ztJDorderData:view")
	@RequestMapping(value = { "list", "" })
	public String list(ZtJDorder ztJDorder, Model model) {
		model.addAttribute("ztJDorder", ztJDorder);

		return "modules/ztJDorder/ztJDorderList";
	}

	

	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ztJDorder:ztJDorderData:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ZtJDorder> listData(ZtJDorder ztJDorder, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		
		
		Page<ZtJDorder> page = ztJDorderService.findPage(new Page<ZtJDorder>(request,
				response), ztJDorder);

		

		return page;
	}

	DictDataService dictDataService;

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ztJDorder:ztJDorderData:view")
	@RequestMapping(value = "form")
	public String form(@ModelAttribute("ztJDorder") ZtJDorder ztJDorder, Model model,
			HttpServletRequest request, HttpServletResponse response) {

		if (ztJDorder.getCreateDate() == null) {
			ztJDorder.setCreateDate(new Date());
		}
	
		model.addAttribute("ztJDorder", ztJDorder);
		

		return "modules/ztJDorder/ztJDorderForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("ztJDorder:ztJDorderData:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ZtJDorder ztJDorder) {

		ztJDorderService.save(ztJDorder);

		return renderResult(Global.TRUE, text("保存订单成功！"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("ztJDorder:ztJDorderData:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ZtJDorder ztJDorder) {
		ztJDorderService.delete(ztJDorder);
		return renderResult(Global.TRUE, text("删除订单成功！"));
	}
}